package example.lesson05_02;

public class TestOverride {
    public static void main(String[] args){
        Person p=new Person(20,"Zhang");
        System.out.println(p);
        Student s=new Student(20,"Zhang","ZSC");
        System.out.println(s+",School:"+s.school);
    }

}
class Person{
    public int age;
    public String name;
    Person(int age,String name){
        this.age=age;
        this.name=name;
    }
    @Override
    public String toString() {
        return "age:" + age + ",name:" + name;
    }
}

//Student是一种Person，是Person的子类，继承了父类Person中定义的属性和功能
//子类是父类的扩展，子类是一种特殊的父类
class Student extends Person{
    public String school;

    Student(int age,String name,String school){
        //子类构造函数中，必须在第一行  调用父类构造函数
        super(age, name);
        this.school=school;

    }
    @Override
    public String toString(){
        return super.toString()+",school"+school;
    }


}
